<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div  class="table-operator" :md="24" :sm="24" style="margin: 0px 0px 20px 0px">
      <a-button v-if="isShow" @click="handleAdd" type="primary" icon="plus">院校报考</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        :scroll="{x:1930}"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="showImage" slot-scope="text, record, index">
          <div v-if="text!=null"
            style="width: 100%;height: 100%;position: relative;padding: 8px;border: 1px solid #d9d9d9;border-radius: 4px;">
            <img style="width: 100%;" :src="imageSrc+'/'+text" :preview="index" >
          </div>
          <div v-else>
            <img style="width: 100%;" src="https://gujianjian20190707.oss-cn-beijing.aliyuncs.com/unknown.png" :preview="index" >
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <SchoolChoose-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>
  import SchoolChooseModal from './modules/SchoolChooseModal'
  import {initDictOptions, filterDictText} from '@/components/dict/JDictSelectUtil'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'

  export default {
    name: 'SchoolChooseList',
    mixins: [JeecgListMixin],
    components: {
      SchoolChooseModal
    },
    data() {
      return {
        isShow:false,
        description: '信息',
        // 表头
        columns: [
          {
            title: '报考学校',
            align: 'center',
            width: 100,
            dataIndex: 'toSchool'

          },
          // {
          //   title: '合作单位',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'belong',
          //   customRender: (text, record, index) => {
          //     //字典值替换通用方法
          //     return filterDictText(this.platformDictOptions, text);
          //   }
          // },
          {
            title: '层次',
            align: 'center',
            width: 100,
            dataIndex: 'level',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.levelDictOptions === '') return ''
              let result = filterDictText(this.levelDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }

          },
          {
            title: '批次',
            align: 'center',
            width: 100,
            dataIndex: 'batch'
          },
          {
            title: '专业',
            align: 'center',
            width: 100,
            dataIndex: 'major'
          },
          {
            title: '学习形式',
            align: 'center',
            width: 100,
            dataIndex: 'learnType',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.learnTypeDictOptions === '') return ''
              let result = filterDictText(this.learnTypeDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }
          },
          {
            title: '学费',
            align: 'center',
            width: 100,
            dataIndex: 'schooling'
          },

          // {
          //   title: '联系地址',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'homeAddress'
          // },
          // {
          //   title: '工作单位',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'workAddress'
          // },
          // {
          //   title: '民族',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'nation'
          // },
          {
            title: '身份证正面',
            align: 'center',
            width: 100,
            dataIndex: 'cardIdTop',
            scopedSlots: {customRender: "showImage"}

          },
          {
            title: '身份证反面',
            align: 'center',
            width: 100,
            dataIndex: 'cardIdBottom',
            scopedSlots: {customRender: "showImage"}

          },
          {
            title: '证件照',
            align: 'center',
            width: 100,
            dataIndex: 'certImage',
            scopedSlots: {customRender: "showImage"}
          },
          {
            title: '前置学历毕业证',
            align: 'center',
            width: 100,
            dataIndex: 'eduImage',
            scopedSlots: {customRender: "showImage"}
          },
          {
            title: '学信网认证',
            align: 'center',
            width: 100,
            dataIndex: 'chsiImage',
            scopedSlots: {customRender: "showImage"}
          },
          {
            title: '异地证明',
            align: 'center',
            width: 100,
            dataIndex: 'otherPlaceImage',
            scopedSlots: {customRender: "showImage"}
          },
          {
            title: '其他证书',
            align: 'center',
            width: 100,
            dataIndex: 'otherCertImage',
            scopedSlots: {customRender: "showImage"}
          },


          // {
          //   title: '备注',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'remark'
          // },
          // {
          //   title: '创建人',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'createBy'
          // },
          {
            title: '操作',
            key: 'operation',
            align: 'center',
            width: 100,
            // fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }],
        url: {
          list: '/student/student/listSchoolChooseByMainId',
          delete: '/student/student/deleteSchoolChoose',
          deleteBatch: '/student/student/deleteBatchSchoolChoose'
        },
        levelDictOptions:'',
        platformDictOptions:'',
        learnTypeDictOptions:'',
      }
    },
    computed:{
      imageSrc:function(r){
        return  `${window._CONFIG['imgDomainURL']}`;
      }
    },
    created(){
      this.initDictConfig();
    },
    methods: {
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record,'e');
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
        this.$refs.modalForm.initOptionsSchool()
      },
      handleDetail:function(record){
        this.$refs.modalForm.edit(record,'d');
        this.$refs.modalForm.title="详情";
        this.$refs.modalForm.disableSubmit = true;
      },
      initDictConfig() {
        //初始化字典 - 性别
        initDictOptions('xc_level').then((res) => {
          if (res.success) {
            this.levelDictOptions = res.result;
          }
        });

        initDictOptions('xc_learn_type').then((res) => {
          if (res.success) {
            this.learnTypeDictOptions = res.result;
          }
        });

        initDictOptions('xc_platform').then((res) => {
          if (res.success) {
            this.platformDictOptions = res.result;
          }
        });
      },
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams()
        getAction(this.url.list, { mainId: params.mainId }).then((res) => {
          if (res.success) {
            console.log("院校报考------>",res)
            // 如果有多于一个报考信息，则不让他显示 新增按钮

            if(res.result.length>=1){
              this.isShow=false
            }else{
              this.isShow=true
            }
            this.dataSource = res.result
          } else {
            this.dataSource = null
          }
        })
      },
      getMain(mainId) {
        this.queryParam.mainId = mainId
        this.loadData(1)
      },
      handleAdd: function() {
        this.$refs.modalForm.add(this.queryParam.mainId)
        this.$refs.modalForm.title = '添加院校报考'
        this.$refs.modalForm.optionsSchool=[]
        this.$refs.modalForm.initOptionsSchool()
      },

    }
  }
</script>
<style scoped>
  .ant-card {
    margin-left: -30px;
    margin-right: -30px;
  }
</style>
